package com.zl.gmadmin.common;

/**
 * 通用状态码
 *
 * @author zhangliang
 * @version 1.0
 * @date 2021/1/25 11:54
 */
public enum  Status implements IStatus {
    /**
     * 成功
     */
    SUCCESS(200, "操作成功"),
    ERROR(500, "操作异常!"),
    LOGOUT(200, "退出成功"),
    UNAUTHORIZED(401, "验证已过期,请重新登录！"),
    ACCESS_DENIED(403, "权限不足！"),
    REQUEST_NOT_FOUND(404, "请求不存在！"),
    HTTP_BAD_METHOD(405, "请求方式不支持！"),
    BAD_REQUEST(400, "请求异常！"),
    PARAM_NOT_MATCH(400, "参数不匹配！"),
    PARAM_NOT_NULL(400, "参数不能为空！"),
    USER_DISABLED(403, "当前用户已被锁定，请联系管理员解锁！"),
    USERNAME_PASSWORD_ERROR(500, "用户名或密码错误！"),
//    TOKEN_EXPIRED(5002, "token 验证已过期，请重新登录！"),
    TOKEN_PARSE_ERROR(500, "token 解析失败，请尝试重新登录！"),
    TOKEN_OUT_OF_CTRL(500, "当前用户已在别处登录，请尝试更改密码或重新登录！"),
    KICKOUT_SELF(500, "无法手动踢出自己，请尝试退出登录操作！"),
    NOT_FIND_LOGIN_INFO(500,"找不到当前登录的信息"),
    CODE_HAS_EXPIRED(500,"验证码已过期"),
    CODE_HAS_ERROR(400,"验证码错误"),
    COLUMN_UNIQ(400,"参数重复,请重新输入"),
    HANDLER_NOFOUND(500,"映射路径不存在，请检查路径是否正确"),
    OLD_PASSWORD(400,"旧密码验证错误，无法修改新密码"),
    UPDATE_PASSWORD_SUCCESS(200,"密码修改成功,请重新登录");


    private Integer code;
    private String message;

    Status(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据code获取状态
     *
     * @param code
     * @return
     */
    public static Status fromCode(Integer code) {
        Status[] statuses = Status.values();
        for (Status s : statuses) {
            if (s.getCode().equals(code)) {
                return s;
            }
        }
        return SUCCESS;
    }

    @Override
    public Integer getCode() {
        return code;
    }


    @Override
    public String getMessage() {
        return message;
    }


    @Override
    public String toString() {
        return String.format(" Status:{code=%s, message=%s} ", getCode(), getMessage());
    }}
